using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using way.model;
using way.util;

namespace way.util
{
    public class WinformUtil
    {
        public void messageShow<T>(Result<T> result, RichTextBox richTextBox)
        {
            ResultCode code = result.status;
            string message = result.message;
            Color color;
            if (ResultCodeExtensions.IsSuccess(code))
            {
                color = Color.Green;
            }
            else
            {
                color = Color.Red;
            }
            richTextBox.SelectionStart = richTextBox.TextLength; // 设置插入点位置到文本末尾
            richTextBox.SelectionLength = 0; // 清除选择区域
            richTextBox.SelectionColor = color;
            richTextBox.AppendText("\r\n" + DateTime.Now.ToString() + "\r\n" + message + "\r\n" + ResultCodeExtensions.GetDesc(code));
            richTextBox.ScrollToCaret();
        }
        public void messageShow(string message,Color status, RichTextBox richTextBox)
        {
            richTextBox.SelectionStart = richTextBox.TextLength; // 设置插入点位置到文本末尾
            richTextBox.SelectionLength = 0; // 清除选择区域
            richTextBox.SelectionColor = status;
            richTextBox.AppendText("\r\n" + DateTime.Now.ToString() + "\r\n" + message);
            richTextBox.ScrollToCaret();
        }
        public void loadContext(string message, Color status, RichTextBox richTextBox)
        {
            richTextBox.SelectionStart = richTextBox.TextLength; // 设置插入点位置到文本末尾
            richTextBox.SelectionLength = 0; // 清除选择区域
            richTextBox.SelectionColor = status;
            richTextBox.AppendText(message);
            richTextBox.ScrollToCaret();
        }
        public void messageShow(ResultCode code, RichTextBox richTextBox)
        {
            Color color;
            if (ResultCodeExtensions.IsSuccess(code))
            {
                color = Color.Green;
            }
            else
            {
                color = Color.Red;
            }
            richTextBox.SelectionStart = richTextBox.TextLength; // 设置插入点位置到文本末尾
            richTextBox.SelectionLength = 0; // 清除选择区域
            richTextBox.SelectionColor = color;
            richTextBox.AppendText("\r\n" + DateTime.Now.ToString() + "\r\n" + ResultCodeExtensions.GetDesc(code));
            richTextBox.ScrollToCaret();
        }
    }
}
